<?php
/*
	Copyright 2006, 2007, 2008, 2009, 2010 Bastiaan Grutters
    
    This file is part of Ages of Strife website.

    Ages of Strife website is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Ages of Strife website is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Ages of Strife website.  If not, see <http://www.gnu.org/licenses/>.
 */
include( '../global/initialize.php' );

aos_header( 'Building details' );

$building_id = formatInput( $_GET[ 'id' ] );

$query = "SELECT * " .
		"FROM buildings " .
		"WHERE building_id = '$building_id'";
$result = mysql_query( $query ) or die( "Query failed : " . mysql_error() );
$row = mysql_fetch_array( $result, MYSQL_ASSOC );
?>
					<div class="blok">
<?php
if( isset( $row[ 'name' ] ) ) {
	$name = $row[ 'name' ];
	$description = $row[ 'description' ];
    print( "<strong>" . translate( $name ) . "</strong><br /><br />\r\n" );
    
    print( translate( 'Gold cost' ) . ": <strong class=\"gold\">" . number_format( $row[ 'gold_cost' ] ) . "</strong><br />\r\n" );
    print( translate( 'Time to build' ) . ": " . $row[ 'time_cost' ] . " days<br />\r\n" );
    print( translate( 'Jobs to build' ) . ": <strong class=\"jobs\">" . $row[ 'construction_jobs' ] . "</strong><br /><br />\r\n" );
    print( translate( 'Food production' ) . ": <strong class=\"food\">" . number_format( $row[ 'food_income' ] ) . "</strong><br />\r\n" );
    print( translate( 'Iron production' ) . ": <strong class=\"iron\">" . number_format( $row[ 'iron_income' ] ) . "</strong><br />\r\n" );
    print( translate( 'Coal production' ) . ": <strong class=\"coal\">" . number_format( $row[ 'coal_income' ] ) . "</strong><br />\r\n" );
    print( translate( 'Jobs' ) . ": <strong class=\"jobs\">" . number_format( $row[ 'jobs' ] ) . "</strong><br />\r\n" );
    print( translate( 'Space' ) . ": <strong class=\"space-used\">" . number_format( $row[ 'space' ] ) . "</strong><br />\r\n" );
    print( translate( 'Houses' ) . ": <strong class=\"houses\">" . number_format( $row[ 'housing' ] ) . "</strong><br />\r\n" );
    print( translate( 'Population growth increase' ) . ": " . round( $row[ 'population_growth' ] * 100, 2 ) . "%<br />\r\n" );
    print( translate( 'Defense bonus' ) . ": <strong class=\"defense-bonus\">" . round( $row[ 'defense_bonus' ] * 100 ) . "%</strong><br />\r\n" );
    print( translate( 'Offense bonus' ) . ": <strong class=\"offense-bonus\">" . round( $row[ 'offense_bonus' ] * 100 ) . "%</strong><br /><br />\r\n" );
	
	if( $row[ 'requires' ] != -1 ) {
		$query2 = "SELECT name, building_id FROM buildings WHERE building_id = " . $row[ 'requires' ];
		$result2 = mysql_query( $query2 ) or die( "Query failed : " . mysql_error() );
		$row2 = mysql_fetch_array( $result2, MYSQL_ASSOC );
	    print( translate( 'Requires building' ) . ": <a href=\"building.php?id=" . $row2[ 'building_id' ] . "\">" . translate( $row2[ 'name' ] ) . "</a><br />\r\n" );
	}
	else {
	    print( translate( 'Requires building' ) . ": " . translate( 'none' ) . "<br />\r\n" );
	}
	
	$query2 = "SELECT name, building_id FROM buildings WHERE requires = '$building_id' ORDER BY name";
	$result2 = mysql_query( $query2 ) or die( "Query failed : " . mysql_error() );
	$num = mysql_numrows( $result2 );
	$i = 0;
	print( translate( 'Allows construction of' ) . ": " );
	if( $num > 0 ) {
		while ( $i < $num ) {
			if( $i != 0 ) {
				print( ", " );
			}
			print( "<a href=\"building.php?id=" . mysql_result( $result2, $i, "building_id" ) . "\">" . translate( mysql_result( $result2, $i, "name" ) ) . "</a>" );
			$i ++;	
		}
	}
	else {
		print( " " . translate( 'none' ) );
	}
	print( "<br />\r\n" );

	print( translate( 'Required upgrade' ) . ": " );
	if( $row[ 'upgrade' ] != -1 ) {
		$query2 = "SELECT name, upgrade_id FROM upgrades WHERE upgrade_id = " . $row[ 'upgrade' ];
		$result2 = mysql_query( $query2 ) or die( "Query failed : " . mysql_error() );
		$row2 = mysql_fetch_array( $result2, MYSQL_ASSOC );
		print( "<a href=\"../upgrade/upgradeinfo.php?id=" . $row2[ 'upgrade_id' ] . "\">" . translate( $row2[ 'name' ] ) . "</a>\r\n" );
	}
	else {
		print( translate( 'none' ) );
	}
	print( "<br />\r\n" );
    
    print( "<br /><strong>" . translate( 'Description' ) . "</strong><br /><pre>\r\n" );
    print( wordwrap( translate( $description ), 80 ) . "</pre><br />\r\n" );
}
else {
	transprint( "Invalid building id supplied." );
}
aos_footer();
?>
